// pages/more/more.js
// pages/more/more.js
const {Data} = require("../../utils/data")
Page({
  data: {
    count:true
  },
  onLoad: async function (options) {
    var urltype = options.urltype
    var module = await import("../../utils/http")
    if(urltype == "hot"){
      var res = await module.MusicHttp.getHotMusic();
      res = this.handleData(res.data.playlists)
      this.setData({count:true})
    }else if(urltype == "newest"){
      var res = await module.MusicHttp.getNewest();
      this.setData({count:false})
      var res = res.data.albums;
    }else if(urltype == "dj"){
      var res = await module.MusicHttp.getDjProgram();
      this.setData({count:true})
      res = this.handleDjData(res.data.result)
    }
    this.setData({songs:res})
  },
  handleData(arr){
    var res = [];
    arr.forEach(item=>{
      var{id,name,coverImgUrl,playCount} = item;
      playCount = Data.HandlePlayCount(playCount);
      res.push({id,name,picUrl:coverImgUrl,playCount});
    })
    return res;
  },
  handleDjData(arr){
    arr.forEach(item=>{
      item.playCount = Data.HandlePlayCount(item.program.listenerCount)
    })
    return arr
  },
  toAlbum(event){
    var id = event.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/album/album?id=${id}`,
    })
  }
})